-- damage_magic_summon2
-- created by xinj
-- 施放伤害类魔法时概率召唤

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,
    -- 触发
    trigger = function(who, prop, targetPos)
        if who.type ~= OBJECT_TYPE_USER then
            return;
        end

        -- 不满足概率
        if DungeonM.getRandSeed("damage_magic_summon2") % 1000 >= prop[3] then
            return;
        end

        -- 如果此时怪物全清了
        if DungeonServiceM.isMonsterClear() then
            DungeonLogM.addLog("怪物全清了，不再进行召唤");
            return;
        end

        local element = tonumber(prop[2]);
        local class = DungeonM.queryElement(element, "class");
        local pos;

        if targetPos and targetPos > 0 then
            pos = SummonM.findSummonPos(targetPos);
        else
            pos = SummonM.findSummonPos();
        end

        -- 找不到位置
        if pos < 0 then
            return;
        end

        local para = { ["class"] = class, ["element"] = element };
        DungeonM.transformGrid(class, pos, GRID_STATE_OPEN, para);
    end,

    record = function(target, prop, path)
        return false;
    end
};
